package com.dsl.dslsuzhou.service.impl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.Method;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.dsl.dslsuzhou.common.ConnectUtils;
import com.dsl.dslsuzhou.model.dto.os.TypePram;
import com.dsl.dslsuzhou.model.dto.os.ZljLoginBo;
import com.dsl.dslsuzhou.model.dto.os.ZljLoginDto;
import com.dsl.dslsuzhou.model.dto.url.ZljUrl;
import com.dsl.dslsuzhou.service.ZljLoginService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;


@Service
public class ZljLoginServiceImpl  implements ZljLoginService {

    @Resource
    private ZljUrl zljUrl;
    @Resource
    private ConnectUtils connectUtils;

    private static String publicKey = "MIIBCgKCAQEA0UUNyDGi8kKaZtzjp533gMCfY/+LReK2by94W9LOmNbiGqyRbRESTWOTKRxqCgjiOJpnSYZMfDh0txCbNZifYlLD448xtJCARLzXBJqjdFER5ct7jVQYjv2tH7E+FCqGiSLxF4qeRJ1ki0UWyKcrqsscOyo9cxu7CJKEdSdOimXoqyXmoZWfN27cUE83SBt8IahRpUQY/3RIM1GxaKzGl4DkpjtSKhct0MCl0v0yM7gmoxJHhpKN3eOahRkCokfjbDfNYA+CRDoQlNjCO9ewHMLlNIm677bS82TmTJA26x8ykxm5Ln8luB9v4eP+NOco52XwjO0UFXW4ddH2XM8XowIDAQAB";
    private static Boolean refresh = false;

    @Override
    public String getZljToken() {
        ZljLoginDto zljLoginDto = new ZljLoginDto();
        zljLoginDto.setRefresh(refresh);
        zljLoginDto.setPublicKey(publicKey);
        TypePram typePost = new TypePram();
        typePost.setMethod(Method.POST);
        String bodyStr = JSONObject.toJSONString(zljLoginDto);
        typePost.setBody(bodyStr);
        HttpResponse result = connectUtils.getExecute(zljUrl.getZljToken(), typePost);
        if (result.isOk()) {
            ZljLoginBo zljLoginBo = JSONUtil.toBean(result.body(), ZljLoginBo.class);
            if (!StringUtils.isEmpty(zljLoginBo.getData())) {
                String data = zljLoginBo.getData();
                return data;
            }
        }
        return "token获取失败";
    }
}
